package com.chockqiu.demo.simpledemo;

import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.chockqiu.html.fontface.HtmlFontFaceHandler;
import com.chockqiu.html.fontface.HtmlTagRegister;

/**
 * @author Administrator
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tvHtml = findViewById(R.id.tvHtml);
        TextView tvHtml2 = findViewById(R.id.tvHtml2);
        TextView tvHtml3 = findViewById(R.id.tvHtml3);
        HtmlTagRegister reg = new HtmlTagRegister();
        HtmlFontFaceHandler fontFace = new HtmlFontFaceHandler("kfont") {

            @Override
            public Typeface onNeedFontFace(String faceName) {
                if (faceName.equalsIgnoreCase("DIN")) {
                    return Typeface.createFromAsset(getAssets(),
                            "DIN_Alternate_Bold.ttf"
                    );
                } else if (faceName.equalsIgnoreCase("YouSheBiaoTiHei")) {
                    return Typeface.createFromAsset(getAssets(),
                            "YouSheBiaoTiHei.ttf"
                    );
                }
                return null;
            }
        };
        reg.registerHtmlTag(fontFace);
        tvHtml.setText(Html.fromHtml("<kfont color='#FF0000' size='16px'>愿有前程可奔赴，1234567890</kfont>", null, reg));
        tvHtml2.setText(Html.fromHtml("<kfont color='#0000FF' face='DIN' size='16dp'>亦有岁月可回首，1234567890</kfont>", null, reg));
        tvHtml3.setText(Html.fromHtml("<kfont color='#00FF00' face='YouSheBiaoTiHei' size='18sp'>且有情深共白头。1234567890</kfont>", null, reg));
    }
}
